package com.drivemanage.controller;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.drivemanage.entry.DriveResult;
import com.drivemanage.service.CarInfoService;

@Controller
@RequestMapping("/carInfo")
public class CarInfoController {

    @Resource
    private CarInfoService carInfo;

    /**
     * 上传图片
     */
    @ResponseBody
    @RequestMapping("/uploadImg.do")
    public DriveResult uploadImg(@RequestParam("carpic") MultipartFile carpic, HttpServletRequest request,
            HttpServletResponse response) throws IOException {
        return carInfo.uploadImg(carpic, request, response);
    }

    @ResponseBody
    @RequestMapping("/addCarsInfo.do")
    public DriveResult addCarsInfo(String carid, double carprice, String pinpai, String chexing, String chexingname,
            String jibie, String fadongji, String biansuxiang, String cheshen, String ckg, String zhouju,
            String youxiang, String zuoweishu, double pailiang, String jinqi, String qigang, String maxmali,
            String maxnj, String ranyoutype, String ranhoubianhao, String gongyou, String paifang, String qudong,
            String zhuli, String qianxuangua, String houxuangua, String qianzhidong, String houzhidong,
            String zhuchezhidong, String yuanguangdeng, String jinguangdeng) {
        return carInfo.addCarsInfo(carid, carprice, pinpai, chexing, chexingname,
                jibie, fadongji, biansuxiang, cheshen, ckg, zhouju,
                youxiang, zuoweishu, pailiang, jinqi, qigang, maxmali,
                maxnj, ranyoutype, ranhoubianhao, gongyou, paifang, qudong,
                zhuli, qianxuangua, houxuangua, qianzhidong, houzhidong,
                zhuchezhidong, yuanguangdeng, jinguangdeng);
    }
    /**
     * 全量查询展示在首页
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping("/getCarInfo.do")
    public DriveResult getCarInfo() throws IOException {
        return carInfo.getCarInfo();
    }
    
    /**
     * 按不同条件查找车辆信息
     * @param name
     * @param type
     * @param price
     * @param t
     * @param ordertype
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping("/getCarInfoOrderBy.do")
    public DriveResult getCarInfoOrderBy(String name,String type,String price,String t,String ordertype ) throws IOException {
        return carInfo.getCarInfoOrderBy(name,type,price,t,ordertype);
    }

    @ResponseBody
    @RequestMapping("/getCarInfoByCarId.do")
    public DriveResult getCarInfoByCarId(String carid) throws IOException {
        return carInfo.getCarInfoByCarId(carid);
    }
}
